﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;

namespace UFIDA.U8.BJSOFT.LF.MES.WEBAPI.DBHelp
{
	// Token: 0x02000015 RID: 21
	public class LogException
	{
		/// <summary>
		/// 打印到日志
		/// </summary>
		/// <param name="filename">文件名</param>
		/// <param name="srs">输出信息</param>
		/// <param name="ilog">总开关是否写日志</param>
		/// <param name="iilog">分开关是否写日志</param>
		// Token: 0x06000079 RID: 121 RVA: 0x00006EF4 File Offset: 0x000050F4
		public static void WriteiLog(string filename, string srs, bool ilog, bool iilog)
		{
			bool flag = ilog || iilog;
			if (flag)
			{
				bool flag2 = string.IsNullOrEmpty(filename);
				if (flag2)
				{
					filename = "异常";
				}
				string logPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\log\\" + DateTime.Now.ToString("yyyy-MM-dd");
				bool flag3 = !Directory.Exists(logPath);
				if (flag3)
				{
					Directory.CreateDirectory(logPath);
				}
				string LogAddress = string.Concat(new string[]
				{
					logPath,
					"\\",
					DateTime.Now.ToString("yyyy-MM-dd"),
					"[",
					filename,
					"]日志.log"
				});
				StreamWriter fs = new StreamWriter(LogAddress, true);
				fs.WriteLine("当前时间：" + DateTime.Now.ToString());
				fs.WriteLine("当前：" + srs);
				fs.WriteLine();
				fs.Close();
			}
		}

		/// <summary>
		/// 将异常打印到LOG文件
		/// </summary>
		/// <param name="ex">异常</param>
		/// <param name="LogAddress">日志文件地址</param>
		// Token: 0x0600007A RID: 122 RVA: 0x00006FF0 File Offset: 0x000051F0
		public static void WriteLog(Exception ex, string sql)
		{
			string logPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\log";
			bool flag = !Directory.Exists(logPath);
			if (flag)
			{
				Directory.CreateDirectory(logPath);
			}
			string LogAddress = logPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "-异常日志.log";
			StreamWriter fs = new StreamWriter(LogAddress, true);
			fs.WriteLine("当前时间：" + DateTime.Now.ToString());
			fs.WriteLine("异常信息：" + ex.Message);
			fs.WriteLine("异常对象：" + ex.Source);
			fs.WriteLine("调用堆栈：\n" + ex.StackTrace.Trim());
			fs.WriteLine("触发语句：" + sql);
			fs.WriteLine();
			fs.Close();
			throw ex;
		}

		// Token: 0x0600007B RID: 123 RVA: 0x000070E4 File Offset: 0x000052E4
		public static string WriteTxtLog(Exception ex)
		{
			string str = ex.ToString();
			LogException.e = str.Substring(0, str.IndexOf('语'));
			return LogException.e;
		}

		// Token: 0x0600007C RID: 124 RVA: 0x0000711C File Offset: 0x0000531C
		public static string WriteTxtEog(Exception ex)
		{
			string str = ex.ToString();
			LogException.eg = str.Substring(0, str.IndexOf('在'));
			return LogException.eg;
		}

		// Token: 0x0600007D RID: 125 RVA: 0x00007154 File Offset: 0x00005354
		public static string WriteTxtSog(string cw)
		{
			LogException.sg = cw;
			return LogException.sg;
		}

		/// <summary>
		/// 错误信息
		/// </summary>
		/// <returns></returns>
		// Token: 0x0600007E RID: 126 RVA: 0x00007174 File Offset: 0x00005374
		public static string exlog()
		{
			bool flag = LogException.e == "";
			string es;
			if (flag)
			{
				es = LogException.eg;
			}
			else
			{
				es = LogException.e;
			}
			bool flag2 = LogException.sg != "";
			if (flag2)
			{
				es = LogException.sg;
			}
			return es;
		}

		/// <summary>
		/// 将异常打印到LOG文件
		/// </summary>
		/// <param name="ex">异常</param>
		/// <param name="LogAddress">日志文件地址</param>
		// Token: 0x0600007F RID: 127 RVA: 0x000071C8 File Offset: 0x000053C8
		public static void WriteLogts(string srs)
		{
			string logPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\log";
			bool flag = !Directory.Exists(logPath);
			if (flag)
			{
				Directory.CreateDirectory(logPath);
			}
			string LogAddress = logPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "-异常日志.log";
			StreamWriter fs = new StreamWriter(LogAddress, true);
			fs.WriteLine("当前时间：" + DateTime.Now.ToString());
			fs.WriteLine("当前：" + srs);
			fs.WriteLine();
			fs.Close();
		}

		/// <summary>
		/// 将异常打印到LOG文件
		/// </summary>
		/// <param name="ex">异常</param>
		/// <param name="LogAddress">日志文件地址</param>
		// Token: 0x06000080 RID: 128 RVA: 0x00007270 File Offset: 0x00005470
		public static void WriteLogTZ(Exception ex, List<string> str)
		{
			string logPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\log";
			bool flag = !Directory.Exists(logPath);
			if (flag)
			{
				Directory.CreateDirectory(logPath);
			}
			string LogAddress = logPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "-异常日志.log";
			StreamWriter fs = new StreamWriter(LogAddress, true);
			fs.WriteLine("当前时间：" + DateTime.Now.ToString());
			fs.WriteLine("异常信息：" + ex.Message);
			fs.WriteLine("异常对象：" + ex.Source);
			fs.WriteLine("调用堆栈：\n" + ex.StackTrace.Trim());
			fs.WriteLine("触发语句：" + str.ToString());
			fs.WriteLine();
			fs.Close();
			throw ex;
		}

		// Token: 0x04000028 RID: 40
		public static bool ilog = Convert.ToBoolean(ConfigurationManager.AppSettings["ilog"].ToString());

		// Token: 0x04000029 RID: 41
		private static string e = "";

		// Token: 0x0400002A RID: 42
		private static string eg = "";

		// Token: 0x0400002B RID: 43
		private static string sg = "";
	}
}
